@layout("/common/_container.html"){
<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	  <div class="layui-form-item">
	  	<!--<div class="layui-inline">-->
	  		<!--<label class="layui-form-label">资质认证</label>-->
	   		<!--<div class="layui-input-block">-->
			     <!--<select name="authState" id="authState">-->
			       <!--<option value="">资质认证</option>-->
			       <!--<option value="0">待审核</option>-->
			       <!--<option value="1">审核通过</option>-->
			       <!--<option value="2">驳回</option>-->
			     <!--</select>-->
             <!--</div>-->
          <!--</div>-->
			<div class="layui-inline">
	      		<label class="layui-form-label">部门名称</label>
				<div class="layui-input-block">
			 	 <input type="text" id="dutyName" name="dutyName" placeholder="部门名称" autocomplete="off" class="layui-input">
				</div>
	       </div>

	  
	    <div class="layui-inline">
	      <button class="layui-btn layuiadmin-btn-useradmin" data-type="reload">
	        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
	      </button>
	    </div>
		  <div class="layui-inline"  >
			  <button class="layui-btn layui-btn-normal layui-btn-radius" id="export" lay-filter="export" lay-submit>
				下载模板
			  </button>
		  </div>

		  <div class="layui-inline" >
			  <button class="layui-btn layui-btn-normal layui-btn-radius" id="exportAll" lay-filter="exportAll" lay-submit>
				  导出数据
			  </button>
		  </div>
		  <div class="layui-inline" >
			  <button class="layui-btn layui-btn-normal layui-btn-radius" id="ReexportAll" lay-filter="ReexportAll" lay-submit>
				导入数据
			  </button>
		  </div>

	    </div>
	  </div>
  <div class="layui-card-body">
	  <div style="padding-bottom: 10px;">
		  <button class="layui-btn layuiadmin-btn-useradmin" data-type="add"><i class="layui-icon layui-icon-add-1"></i>添加部门</button>
	  </div>
  <table class="layui-hidden" id="table" lay-filter="table"></table>
	  <script type="text/html" id="oper">
		  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" title="编辑">编辑</a>
		  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" title="删除">删除</a>
	  </script>
  </div>
</div>

<script>
layui.config({
	base: Feng.ctxPath + "/static/layuiadmin/" //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['index', 'layer','table','form','upload'],function(){
	var $ = layui.$
  	,form = layui.form
  	,table = layui.table
  	,upload = layui.upload;

	var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });

    var uploadInst = upload.render({
        elem: '#ReexportAll' //绑定元素
        ,url: Feng.ctxPath +'user/importExcelForType' //上传接口
        ,done: function(res){
            //上传完毕回调
            console.log(res)
			// console.log(res.data.data)
            var phone=null
			var html=""
			if (res.data.length!=0){
                for(var i = 0; i < res.data.length; i++) {
                    phone=res.data[i].phone
					html=html+'<div style="padding: 20px 100px;">'+'手机号：'+ phone +'</div>'
                }
                layer.open({
                    type: 1
                    ,content: html
                    ,title: "无法导入的手机号"
                    ,btn: '关闭'
                    ,btnAlign: 'c' //按钮居中
                    ,shade: 0 //不显示遮罩
                    ,yes: function(){
                        layer.closeAll();
                    }
                });

            }else {
                Feng.success("导入成功!");
			}
        }
        ,accept: 'file'
        ,exts:'xlsx|xls'
        ,error: function(){
            //请求异常回调
        }
    });




    form.on('submit(export)', function (data) {
        var field = data.field; //获取提交的字段
        //墨绿深蓝风
        layer.alert('正在下载模板. . .完成后请手动关闭弹窗111', {
            skin: 'layui-layer-lan'
            ,closeBtn: 0
            //,anim: 4 //动画类型
        });

        //模拟form表单提交导出
        postExcelFile(field, Feng.ctxPath + "/fdcDuty/downloadExample");
    });
    form.on('submit(exportAll)', function (data) {
        var field = data.field; //获取提交的字段
        //墨绿深蓝风
        layer.alert('正在导出Excel. . .完成后请手动关闭弹窗', {
            skin: 'layui-layer-lan'
            ,closeBtn: 0
            //,anim: 4 //动画类型
        });

        //模拟form表单提交导出
        postExcelFile(field, Feng.ctxPath + "/fdcDuty/exportAll");
    });

    //模拟form表单提交导出
    function postExcelFile(params, url) { //params是post请求需要的参数，url是请求url地址
        var form = document.createElement("form");
        form.style.display = 'none';
        form.action = url;
        form.method = "post";
        document.body.appendChild(form);

        for(var key in params){
            var input = document.createElement("input");
            input.type = "hidden";
            input.name = key;
            input.value = params[key];
            form.appendChild(input);
        }

        form.submit();
        form.remove();
    }

	table.render({
	    elem: '#table'
	    ,url: Feng.ctxPath + '/fdcDuty/list'
	    ,cellMinWidth: 100
	    ,height: 'full-168'
	    ,cols: [[
	        {title: '部门名称', field:'dutyName'},
	        {title: '创建时间', field:'createTime'},
	        {title: '更新时间', field:'updateTime'},
            {title: '操作',fixed: 'right', width:240, align:'center',fixed: 'right', toolbar: '#oper'}
	    ]]
	    ,page:true
	    ,loading:true
	    ,text: {
	        none: '暂无相关数据' 
	      }
	    ,done: function(res){
	    	layer.close(loadingIndex);
        }
	});
	
	//事件
	var active = {
		//加载
	   	reload: function(){
	       var dutyName = $('#dutyName').val();

	       var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	       //执行表格重载
	       table.reload('table', {
	    	 height: 'full-168' //设置高度
	    	 ,where: {
                   dutyName:dutyName
	         }
	       ,page:true
	       ,done: function(res){
		    	layer.close(loadingIndex);
	        }
	      });
	    },
        add: function(){
            var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
            layer.open({
                type: 2
                ,title: '添加部门'
                ,content: Feng.ctxPath + '/fdcDuty/duty_add'
                ,maxmin: true
                ,area: ['600px', '400px']
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    var iframeWindow = window['layui-layer-iframe'+ index]
                        ,submitID = 'eleFence-submit'
                        ,submit = layero.find('iframe').contents().find('#'+ submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                        var field = data.field; //获取提交的字段

                        var loading2 = layer.load(2);
                        var ajax = new $ax(Feng.ctxPath + "/fdcDuty/add", function (data) {
                            Feng.success("添加成功!");
                            table.reload('table',{
                                done: function(res){
                                    layer.close(loadingIndex);
                                }
                            }); //数据刷新
                            layer.close(loading2); //关闭弹层
                            layer.close(index); //关闭弹层
                        }, function (data) {
                            Feng.error("添加失败!" + data.responseJSON.message + "!");
                        },true);
                        ajax.setData(field);
                        ajax.start();
                    });
                    submit.trigger('click');
                }
                ,btn2: function(index, layero){
                    layer.close(loadingIndex);
                }
                ,cancel:function(index, layero){
                    layer.close(loadingIndex);
                }
            });
        }
   };
    //监听工具条
    table.on('tool(table)', function(obj){
        var data = obj.data;
        if(obj.event === 'del') {
            layer.confirm('是否删除部门信息？', function (index) {
                var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0, shade: 0.01});
                var ajax = new $ax(Feng.ctxPath + "/fdcDuty/delete", function (data) {
                    Feng.success("删除成功!");
                    table.reload('table', {
                        done: function (res) {
                            layer.close(loadingIndex);
                        }
                    }); //数据刷新
                    layer.close(index); //关闭弹层
                }, function (data) {
                    Feng.error("删除失败!" + data.responseJSON.message + "!");
                }, true);
                ajax.set("id", data.id);
                ajax.start();
            });
        }
        else if (obj.event === 'edit'){
            var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
            layer.open({
                type: 2
                ,maxmin: true
                ,title: '修改用户信息'
                ,content: Feng.ctxPath + '/fdcDuty/updateDutyById/'+data.id
                ,area: ['600px', '400px']
                ,btn: ['提交', '取消']
                ,yes: function(index, layero){
                    var iframeWindow = window['layui-layer-iframe'+ index]
                        ,submitID = 'eleFence-submit'
                        ,submit = layero.find('iframe').contents().find('#'+ submitID)
                        ,pointsSubmit = layero.find('iframe').contents().find('#points-submit');
                    pointsSubmit.trigger('click');

                    //监听提交
                    iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                        var field = data.field; //获取提交的字段
                        var loading2 = layer.load(2);
                        //alert(JSON.stringify(field))
                        var ajax = new $ax(Feng.ctxPath + "/fdcDuty/updateDuty", function (data) {
                            Feng.success("修改成功!");
                            table.reload('table',{
                                done: function(res){
                                    layer.close(loadingIndex);
                                }
                            }); //数据刷新
                            layer.close(loading2); //关闭弹层
                            layer.close(index); //关闭弹层
                        }, function (data) {
                            Feng.error("修改失败!" + data.responseJSON.message + "!");
                        },true);
                        ajax.setData(field);
                        ajax.start();

                    });

                    submit.trigger('click');
                }
                ,btn2: function(index, layero){
                    layer.close(loadingIndex);
                }
                ,cancel:function(index, layero){
                    layer.close(loadingIndex);
                }
            });
		}
	});
  
   $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
     var type = $(this).data('type');
     active[type] ? active[type].call(this) : '';
   });
});
</script>
@}
